package com.alibaba.nacos.config.server.jpa.entity;

import java.time.LocalDateTime;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

/**
 * @author
 * @date 2020-03-08 23:31
 * config_info
 */
@Entity
@Table(name = "NACOS_CONFIG_INFO", uniqueConstraints = {
    @UniqueConstraint(name = "UK_CONFIGINFO_DATAGROUPTENANT", columnNames = {
        "DATA_ID", "GROUP_ID", "TENANT_ID"
    })
})
public class ConfigInfoEntity extends AbstractEntity {

    private static final long serialVersionUID = 1L;

    public ConfigInfoEntity () {}



    @Column(name = "APP_NAME")
    private String appName;

    @Column(name = "C_DESC", length = 256)
    private String cDesc;

    @Column(name = "C_SCHEMA")
    @Lob
    private String cSchema;

    @Column(name = "C_USE")
    private String cUse;

    /**
     * content
     */
    @Column(name = "CONTENT", nullable = false)
    @Lob
    private String content;

    /**
     * data_id
     */
    @Column(name = "DATA_ID", nullable = false)
    private String dataId;

    @Column(name = "EFFECT")
    private String effect;

    /**
     * 创建时间
     */
    @Column(name = "GMT_CREATE", nullable = false)
    @CreatedDate
    private LocalDateTime gmtCreate;

    /**
     * 修改时间
     */
    @Column(name = "GMT_MODIFIED", nullable = false)
    @LastModifiedDate
    private LocalDateTime gmtModified;

    @Column(name = "GROUP_ID")
    private String groupId;

    /**
     * md5
     */
    @Column(name = "MD5")
    private String md5;

    /**
     * source ip
     */
    @Column(name = "SRC_IP")
    private String srcIp;

    /**
     * source user
     */
    @Column(name = "SRC_USER")
    @Lob
    private String srcUser;

    /**
     * 租户字段
     */
    @Column(name = "TENANT_ID")
    private String tenantId;

    @Column(name = "TYPE")
    private String type;

    public ConfigInfoEntity setAppName(String appName){
        this.appName = appName;
        return this;
    }

    public String getAppName(){
        return appName;
    }

    public ConfigInfoEntity setCDesc(String cDesc){
        this.cDesc = cDesc;
        return this;
    }

    public String getCDesc(){
        return cDesc;
    }

    public ConfigInfoEntity setCSchema(String cSchema){
        this.cSchema = cSchema;
        return this;
    }

    public String getCSchema(){
        return cSchema;
    }

    public ConfigInfoEntity setCUse(String cUse){
        this.cUse = cUse;
        return this;
    }

    public String getCUse(){
        return cUse;
    }

    public ConfigInfoEntity setContent(String content){
        this.content = content;
        return this;
    }

    public String getContent(){
        return content;
    }

    public ConfigInfoEntity setDataId(String dataId){
        this.dataId = dataId;
        return this;
    }

    public String getDataId(){
        return dataId;
    }

    public ConfigInfoEntity setEffect(String effect){
        this.effect = effect;
        return this;
    }

    public String getEffect(){
        return effect;
    }

    public ConfigInfoEntity setGmtCreate(LocalDateTime gmtCreate){
        this.gmtCreate = gmtCreate;
        return this;
    }

    public LocalDateTime getGmtCreate(){
        return gmtCreate;
    }

    public ConfigInfoEntity setGmtModified(LocalDateTime gmtModified){
        this.gmtModified = gmtModified;
        return this;
    }

    public LocalDateTime getGmtModified(){
        return gmtModified;
    }

    public ConfigInfoEntity setGroupId(String groupId){
        this.groupId = groupId;
        return this;
    }

    public String getGroupId(){
        return groupId;
    }

    public ConfigInfoEntity setMd5(String md5){
        this.md5 = md5;
        return this;
    }

    public String getMd5(){
        return md5;
    }

    public ConfigInfoEntity setSrcIp(String srcIp){
        this.srcIp = srcIp;
        return this;
    }

    public String getSrcIp(){
        return srcIp;
    }

    public ConfigInfoEntity setSrcUser(String srcUser){
        this.srcUser = srcUser;
        return this;
    }

    public String getSrcUser(){
        return srcUser;
    }

    public ConfigInfoEntity setTenantId(String tenantId){
        this.tenantId = tenantId;
        return this;
    }

    public String getTenantId(){
        return tenantId;
    }

    public ConfigInfoEntity setType(String type){
        this.type = type;
        return this;
    }

    public String getType(){
        return type;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("ConfigInfoEntity = {");

        if (appName != null){
            sb.append("appName = ").append(appName).append(", ");
        }
        if (cDesc != null){
            sb.append("cDesc = ").append(cDesc).append(", ");
        }
        if (cSchema != null){
            sb.append("cSchema = ").append(cSchema).append(", ");
        }
        if (cUse != null){
            sb.append("cUse = ").append(cUse).append(", ");
        }
        if (content != null){
            sb.append("content = ").append(content).append(", ");
        }
        if (dataId != null){
            sb.append("dataId = ").append(dataId).append(", ");
        }
        if (effect != null){
            sb.append("effect = ").append(effect).append(", ");
        }
        if (gmtCreate != null){
            sb.append("gmtCreate = ").append(gmtCreate).append(", ");
        }
        if (gmtModified != null){
            sb.append("gmtModified = ").append(gmtModified).append(", ");
        }
        if (groupId != null){
            sb.append("groupId = ").append(groupId).append(", ");
        }
        if (id != null){
            sb.append("id = ").append(id).append(", ");
        }
        if (md5 != null){
            sb.append("md5 = ").append(md5).append(", ");
        }
        if (srcIp != null){
            sb.append("srcIp = ").append(srcIp).append(", ");
        }
        if (srcUser != null){
            sb.append("srcUser = ").append(srcUser).append(", ");
        }
        if (tenantId != null){
            sb.append("tenantId = ").append(tenantId).append(", ");
        }
        if (type != null){
            sb.append("type = ").append(type);
        }

        sb.append("}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ConfigInfoEntity that = (ConfigInfoEntity) o;
        return Objects.equals(dataId, that.dataId) &&
            Objects.equals(groupId, that.groupId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(dataId, groupId);
    }
}
